home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / eiffel / smalleif.97 / se.t / SmallEiffel / lib_test / test_string1.e < prev    next >
Encoding:
Text File  |  1996-05-02  |  4.7 KB  |  192 lines

  1. -- Part of SmallEiffel -- Read DISCLAIMER file -- Copyright (C) 
  2. -- Dominique COLNET and Suzanne COLLIN -- colnet@loria.fr
  3. --
  4. class TEST_STRING1
  5.    
  6. creation {ANY}
  7.    make
  8.    
  9. feature {ANY}
  10.    
  11.    make is
  12.       local
  13.      s, s2: STRING;
  14.      i: INTEGER;
  15.      words: ARRAY[STRING];
  16.       do
  17.      !!s.blank(0); ------------------------------------------------
  18.      is_true(s.count = 0);
  19.      s.blank(1);
  20.      is_true(s.count = 1);
  21.      is_true(s.item(1) = ' ');
  22.      s.put('a',1); 
  23.      is_true(s.count = 1);
  24.      is_true(s.item(1) = 'a');
  25.      
  26.      
  27.      !!s.blank(4); ------------------------------------------------
  28.      is_true(s.count = 4);
  29.      from  
  30.         i := 1;
  31.      until
  32.         i > s.count
  33.      loop
  34.         is_true(s.item(i) = ' ');
  35.         i := i + 1;
  36.      end;
  37.      
  38.      is_true(equal("","")); --------------------------------------
  39.      is_true(not equal(" ",""));
  40.          !!s.blank(3);
  41.          s.put('a',2);
  42.          is_true(equal(" a ",s));
  43.          is_true(equal(s," a "));
  44.      
  45.          s := ""; ----------------------------------------------------
  46.      is_true(s.count = 0);
  47.      s.extend('x');
  48.      is_true(s.count = 1);
  49.      is_true(s.item(1) = 'x');
  50.  
  51.          s := "1"; ---------------------------------------------------
  52.      is_true(s.count = 1);
  53.      is_true(s.item(1) = '1');
  54.      s.extend('x');
  55.      is_true(s.count = 2);
  56.      is_true(s.item(1) = '1');
  57.      is_true(s.item(2) = 'x');
  58.      is_true(equal("1x",s));
  59.  
  60.      !!s.blank(3); ------------------------------------------------
  61.      s.put('h',2);
  62.      is_true(equal(" h ",s));
  63.      s.put(' ',2);
  64.      is_true(not equal(" h ",s));
  65.      is_true(equal(s,"   "));
  66.          s.blank(3);
  67.      is_true(equal(s,"   "));
  68.  
  69.      !!s.copy("ab"); --------------------------------------------
  70.      is_true(s.count = 2);
  71.          is_true(equal("ab",s));
  72.      s.copy("cdef");
  73.      is_true(equal("cdef",s));
  74.      s.copy("a");
  75.      is_true(equal("a",s));
  76.      
  77.      s := ""; ----------------------------------------------------
  78.      is_true(s.count = 0);
  79.      !!s.copy(s);
  80.      is_true(s.count = 0);
  81.      s.extend('a');
  82.      is_true(s.count = 1);
  83.      is_true(s.item(1) = 'a');
  84.      
  85.      s2 := "a"; --------------------------------------------------
  86.      s := clone(s2);
  87.      is_true(s.count = 1);
  88.      is_true(s2.count = 1);
  89.      is_true(s.item(1) = 'a');
  90.      s2.put('b',1);
  91.      is_true(s2.item(1) = 'b');
  92.      is_true(s.item(1) = 'a');
  93.      
  94.      s := "abc"; -------------------------------------------------
  95.      s2 := clone(s);
  96.      is_true(equal(s,s2));
  97.      s.put('x',2);
  98.      is_true(not equal(s,s2));
  99.      is_true(equal(Void,clone(Void))); ---------------------------
  100.         
  101.      !!s.blank(0); ------------------------------------------------
  102.      is_true(equal("",s));
  103.      !!s.blank(2);
  104.      is_true(equal("  ",s));
  105.      s := "aaa";
  106.      s.blank(2);
  107.      is_true(equal("  ",s));
  108.       
  109.      s := ""; ----------------------------------------------------
  110.      is_true(equal(clone(""),s));
  111.      !!s.blank(2);
  112.      is_true(equal("  ",s));
  113.      s := "aaa";
  114.      s.blank(2);
  115.      is_true(equal("  ",s));
  116.      is_true(equal("abc","abc"));
  117.      
  118.      !!s.copy("kiki"); ------------------------------------------
  119.      is_true(equal(s,"kiki"));
  120.      s.copy(s);
  121.      -- std_output.put_string("Coucou %N");
  122.      is_true(equal(s,"kiki"));
  123.      s.copy("3");
  124.      is_true(equal(s,"3"));
  125.       
  126.            !!s.copy("kiki"); ------------------------------------------
  127.      s.clear;
  128.      is_true(equal(s,""));
  129.       
  130.      s := "123456789";
  131.      s.shrink(1,7);
  132.      is_true(("1234567").is_equal(s));
  133.      s.shrink(2,7);
  134.      is_true(("234567").is_equal(s));
  135.       
  136.      is_true((" +234 ").to_integer = 234);
  137.      is_true((" - 67").to_integer = -67);
  138.       
  139.            is_true(("+ 234.").to_real = 234.0);
  140.      is_true(("+1234").to_real = 1234.0);
  141.            is_true((" +234.22").to_real <= 234.221);
  142.            is_true((" +234.22").to_real >= 234.219);
  143.      is_true((" - 67.0 %N").to_real = -67);
  144.      
  145.      is_true((".5").to_real = 0.5);
  146.      
  147.      is_true(str1.is_equal(str2));
  148.      is_true(str1 /= str2);
  149.       
  150.      !!s.make(10);
  151.      is_true(s.count = 0);
  152.      is_true(s.capacity <= 10);
  153.      
  154.      words := ("un machin").split;
  155.      is_true(words.count = 2);
  156.      is_true(equal(words,<<"un","machin">>));
  157.       
  158.            words := ("   un machin  ").split;
  159.      is_true(equal(words,<<"un","machin">>));
  160.       
  161.            is_true(("   ").split = Void);
  162.       
  163.      is_true(("%/32/").first = ' ');
  164.      is_true(("%/122/").first = 'z');
  165.      is_true(("%/123/").first = '{');
  166.      is_true(("%/207/").first = '%/207/');
  167.      is_true(("%/255/").first = '%/255/');
  168.      is_true(("%/206/").first = '%/206/');
  169.      is_true(("%/92/").first = '%/92/');
  170.      is_true(("%/92/").first = '\');
  171.      is_true(("%/92/").first = '%H');
  172.      is_true(("\").first = '%H');
  173.       end;
  174.    
  175.    str1, str2: STRING is "Ouupps ...";
  176.    
  177.    is_true(b: BOOLEAN) is
  178.       do
  179.      cpt := cpt + 1;
  180.      if not b then
  181.         std_output.put_string("TEST_STRING1: ERROR Test # ");
  182.         std_output.put_integer(cpt);
  183.         std_output.put_string("%N");
  184.      else
  185.         --std_output.put_string("Yes %N");
  186.      end;
  187.       end;
  188.    
  189.    cpt: INTEGER;
  190.    
  191. end -- TEST_STRING1
  192.